package com.tarena.csmall.sentinel.demo01;

import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.ArrayList;
import java.util.List;

/**
 * @author java@tedu.cn
 * @version 1.0
 */
@SpringBootApplication
public class SentinelD1App {
    public static void main(String[] args) {
        SpringApplication.run(SentinelD1App.class,args);
        //启动类,定义限流规则,熔断规则,每个规则,都针对自己的资源设置
        List<FlowRule> rules=new ArrayList<>();
        FlowRule flowRule=new FlowRule();
        //告诉这个流量控制规则,你限制的资源是谁
        flowRule.setResource("sayHi");
        //设置规则 qps上限是1/s count是上限阈值
        flowRule.setCount(1500);
        //设置count类型 1=qps 0=并发
        flowRule.setGrade(1);
        rules.add(flowRule);
        //注册在sentinel组件中
        FlowRuleManager.loadRules(rules);
    }
}
